<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>await的基本用法</title>
</head>
<body>
    
</body>
<script>
    function demo(name){
        return new Promise((resolve,reject)=>{
            setTimeout(()=>{
                resolve(name)
                console.log(name);
            },1000)
        })
    }
    demo('zs')

    //await只能在async函数中才能使用，否则会报错
    //await后面跟着一定是promise对象

    async function demo2(){
        let name = await ('jack')
        console.log('hello',name);
    }

    demo2()

    /*
    *执行规则
    首先调用demo2函数
    遇到了await表示代码在这暂停了
    不在向下执行，等待promise对象执行完毕
    拿到了promise对象的resolve或者reject返回值再继续执行
    */
</script>
</html>